from django.db import models
from django.contrib.auth.models import User
from barrelhouse.core.vendors.models import vendor_account

class second_level_domain(models.Model):
    '''domains requiring registration.  will likely have to be extended by any module that interfaces with a registrar API'''


    name = models.CharField(max_length=96, unique=True, db_index=True, help_text="Domain Name")
    registration_date = models.DateField(db_index=True, help_text="Date Domain was issued", verbose_name="Registration Date")
    expiration_date = models.DateField(db_index=True, help_text="Date Domain Expires", verbose_name="Current Expiration Date")
    registrar = models.ForeignKey(vendor_account, help_text="Account Domain was registered under", verbose_name="Registrar Account")
    primary_contact = models.ForeignKey(User, help_text="Internal Primary Contact for this domain", verbose_name="Primary Contact")
    notes = models.TextField(null=True, blank=True, help_text="Associated Notes for this domain")

    def get_full_name(self):
        return self.name

    def __unicode__(self):
        return self.get_full_name()

    def get_absolute_url(self):
        return "/domains/%s" % self.__unicode__

    class Meta:
        verbose_name = "Second Level Domain"

class third_level_domain(models.Model):
    '''3rd level (and-worse) domains associated with a root domain.  this relationship is easy to gum up...'''

    name = models.CharField(max_length=96, db_index=True, help_text="Domain Name")
    root_domain = models.ForeignKey(second_level_domain, verbose_name="Root Domain", help_text="domain this sub-domain exists under")
    registration_date = models.DateField(db_index=True, help_text="Date Domain was issued", verbose_name="Registration Date")
    primary_contact = models.ForeignKey(User, help_text="Internal Primary Contact for this domain", verbose_name="Primary Contact")
    notes = models.TextField(null=True, blank=True, help_text="Associated Notes for this domain")

    def get_full_name(self):
        return self.name + " " + unicode(self.root_domain)

    def get_absolute_url(self):
        return "/third_level_domains/%s" % self.id

    def __unicode__(self):
        return self.get_full_name()

    class Meta:
        verbose_name = "Third Level Domain"

